function datas(){
	var year = new Date().getFullYear();
	var month = new Date().getMonth()+1;
	var data = new Date().getDate();
	if(parseInt(month)<10){
		month = "0"+month;
	}
	if(parseInt(data)<10){
		data = "0"+data;
	}
	var DATE = (year+"-"+month+"-"+data);
	return DATE;
}

//判断这个人是否有考勤卡 考勤前置
function sfKQK(EMPID){
	$.ajax({
		url:"kao-qin-zhu-ye-qian-zhi",
		type:"post",
		data:{"EMPID":EMPID},
		success:function(data){
			var ss = parseInt(data);
			if(ss==0){
				$(".zhu_ye_wjr").removeClass("hide");
				$(".zhu_ye_qian_dao").addClass("hide");
				$(".zhu_ye_qian_tui").addClass("hide");
				$(".zhu_ye_qin_jia").addClass("hide");
				$(".zhu_ye_jia_ban").addClass("hide");
			}else if(ss==1){
				$(".zhu_ye_wjr").addClass("hide");
				qiandaocishu(EMPID);
			}
		}
	});
}

//签到次数
function qiandaocishu(EMPID){
	var DATE = datas();
	$.ajax({
		url:"kao-qin-zhu-ye-dang-ri-qian-dao-ci-shu",
		type:"post",
		data:{"EMPID":EMPID,"DATE":DATE},
		success:function(data){
			var ss = parseInt(data);
			if(ss==0){
				$(".zhu_ye_qian_dao").removeClass("hide");
				$(".zhu_ye_qian_tui").addClass("hide");
			}else if(ss==1){
				$(".zhu_ye_qian_dao").addClass("hide");
				$(".zhu_ye_qian_tui").removeClass("hide");
			}else if(ss==2){
				$(".zhu_ye_qian_dao").addClass("hide");
				$(".zhu_ye_qian_tui").addClass("hide");
			}
		}
	});
}

//数据
function shuju(EMPID,DATE){
	$.ajax({
		url:"kao-qin-zhu-ye-shu-ju-tong-ji",
		type:"post",
		data:{"EMPID":EMPID,"DATE":DATE},
		success:function(data){
			$(".kao_qin_zhu_ye_name").val(data["empname"]);
			$(".kao_qin_zhu_ye_banzu").val(data["temname"]);
			$(".kao_qin_zhu_ye_banci").val(data["shfname"]);
			$(".kao_qin_zhu_ye_bumen").val(data["deptname"]);
			$(".kao_qin_zhu_ye_da_ke_ci_shu").val(data["qdcs"]);
			$(".kao_qin_zhu_ye_shang_ban_shi_chang").val(data["RESTIME"]);
			$(".kao_qin_zhu_ye_qing_jia_ci_shu").val(data["QJCiShu"]);
			$(".kao_qin_zhu_ye_jia_ban_shi_chang").val(data["JBShuChang"]);
		}
	});
}


$(function(){
	var empid = $(".He_text_t").attr("id");
	sfKQK(empid);
	var year = new Date().getFullYear();
	var month = new Date().getMonth()+1;
	var date = (year+"-"+month);
	shuju(empid,date);
	
//	$("#KaoQinQianDao").click(function(){
//		
//	});
	//签到
	$("#KaoQinQianDao").click(function(){
		$.ajax({
			url:"updateKaoQinShuJu",
			type:"post",
			data:{"resid":null,"empid":empid,"rsnreason":"签到","rsnrem":null},
			success:function(data){
				var jieguo = parseInt(data);
				if(jieguo==0){
					alert("加班签到成功");
				}else if(jieguo==1){
					$.ajax({
						url:"savecalendar",
						type:"post",
						data:{Iremind:"签到","imouthyear":timestampformat()},
						success:function(data){
							addcalend();
						}
					});
					alert("签到成功");
				}else if(jieguo==2){
					alert("系统显示当前时间您已请假，不能签到！");
				}
				updateUC();
			}
		});
	});
	//签退
	$("#KaoQinQianTui").click(function(){
		$.ajax({
			url:"updateKaoQinShuJu",
			type:"post",
			data:{"resid":null,"empid":empid,"rsnreason":"签退","rsnrem":null},
			success:function(data){
				var jieguo = parseInt(data);
				if(jieguo==0){
					alert("加班签退成功");
				}else if(jieguo==1){
					alert("签退成功");
				}else if(jieguo==2){
					alert("系统显示当前时间您已请假，不能签退！");
				}
				updateUC();
			}
		});
	});
	//请假
	$("#KaoQinQinJia").click(function(){
		$('#QinJiaZhongLeiXZ').combobox({
			url:'QinJiaZhongLeicsh',
			valueField:'TYPEID',
			formatter:function(row){
	               row.TYPEZL = row.TYPEZL+"（"+row.TYPEXZ+")";
	               if(row.TYPETIME==null || row.TYPETIME=="null" || row.TYPETIME==""){
	            	   
	               }else{
	            	   row.TYPEZL += "（"+row.TYPETIME+")";
	               }
	               return row.TYPEZL;
	        },
			textField:'TYPEZL',
		});
		$("#QinJiaTianJiawin").window("open");
		$("#QinJiaRen").val($(".He_text_t_name").text());
	});
	
	//新增请假
	$("#updateaddQJ").click(function(){
		var TYPEID = $("#QinJiaZhongLeiXZ").val();
		if(TYPEID==null || TYPEID=="null" || TYPEID==""){
			return alert("请选择请假种类！");
		}
		var LAEMINTIME = $("#LAEMINTIMEXZ").val();
		var LAEMAXTIME = $("#LAEMAXTIMEXZ").val();
		var LAEREM = $("#LAEREMXZ").val();
		$.ajax({
			url:"updateQJ",
			type:"post",
			data:{"EMPID":empid,"TYPEID":TYPEID,"LAEMINTIME":LAEMINTIME,"LAEMAXTIME":LAEMAXTIME,"LAEREM":LAEREM},
			success:function(data){
				var jieguo = parseInt(data);
				if(jieguo==0){
					alert("请假申请提交成功");
					$("#QinJiaTianJiawin").window("close");
				}else if(jieguo==1){
					alert("系统显示当前时间段您已请过假，不能再请假了！");
				}else if(jieguo==2){
					alert("请输入正确的前后时间");
				}
				
				updateUC();
			}
		});
	});

	//加班
	$("#KaoQinJiaBan").click(function(){
		$('#JiaBanYuanYin').combobox('reload');
		$("#JiaBanShenQinwin").window("open");
		$("#JiaBanRen").val($(".He_text_t_name").text());
	});
	
	$("#updateaddJB").click(function(){
		var RSNID = $("#JiaBanYuanYin").val();
		var QTSTIME = $("#JiaBanRiQi").val();
		var QTSREM = $("#QTSREM").val();
		$.ajax({
			url:"updateJiaBan",
			type:"post",
			data:{"EMPID":empid,"RSNID":RSNID,"QTSTIME":QTSTIME,"QTSREM":QTSREM},
			success:function(data){
				if(data=="-1"){
					alert("系统显示，您输入的时间以申请加班了")
				}else{
					alert("申请成功");
					$("#JiaBanShenQinwin").window("close");
					updateUC();
				}
			}
		});
	});
});

function updateUC(){
	adds("签到请假","zx/kao-qin-zhu-ye");
}

 
//js获取timestamp
function timestampformat() {
	var timestamp=Math.round(new Date().getTime());
    return (new Date(timestamp)).format("yyyy-MM-dd hh:mm:ss");
}
Date.prototype.format = function(format) {
    var o = {
        "M+": this.getMonth() + 1,
        // month
        "d+": this.getDate(),
        // day
        "h+": this.getHours(),
        // hour
        "m+": this.getMinutes(),
        // minute
        "s+": this.getSeconds(),
        // second
        "q+": Math.floor((this.getMonth() + 3) / 3),
        // quarter
        "s+": this.getMilliseconds()
        // millisecond
    };
    if (/(y+)/.test(format) || /(Y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
};